package com.eco.fanliapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.dao.AppCashSchemeMapper;
import com.eco.fanliapp.entity.AppCashScheme;
import com.eco.fanliapp.service.ICashschemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CashschemeServiceImpl extends ServiceImpl<AppCashSchemeMapper, AppCashScheme> implements ICashschemeService {

    @Autowired
    private AppCashSchemeMapper cashschemeMapper;

    /**
     * 查询提现方案列表
     *
     * @param appCashscheme 提现方案信息
     * @return 提现方案集合
     */
    @Override
    public ServerResponse<List<AppCashScheme>> selectAppCashschemeList(AppCashScheme appCashscheme) {
        List<AppCashScheme> appCashschemes = cashschemeMapper.selectAppCashschemeList(appCashscheme);
        if (appCashschemes == null ){
            return ServerResponse.createByErrorMessage("查询出现错误");
        }
        return ServerResponse.createBySuccess("查询成功",appCashschemes);
    }

    /**
     * 新增提现方案
     *
     * @param appCashscheme 提现方案信息
     * @return 结果
     */
    @Override
    public ServerResponse<List> insertAppCashscheme(AppCashScheme appCashscheme) {

        int cashschemeNum = cashschemeMapper.insertAppCashscheme(appCashscheme);
        if (cashschemeNum == 1){
            return ServerResponse.createBySuccess("新增方案成功",cashschemeMapper.selectAppCashschemeList(null));
        }
        return ServerResponse.createByErrorMessage("新增方案失败");
    }

    /**
     * 修改提现方案
     *
     * @param appCashscheme 提现方案信息
     * @return 结果
     */
    @Override
    public ServerResponse updateAppCashscheme(AppCashScheme appCashscheme) {
        int cashschemeNum = cashschemeMapper.updateAppCashscheme(appCashscheme);
        if (cashschemeNum == 1){
            return ServerResponse.createBySuccess("修改方案成功",cashschemeMapper.selectAppCashschemeList(null));
        }
        return ServerResponse.createByErrorMessage("修改方案失败");
    }

    /**
     * 删除提现方案
     *
     * @param appCashschemeById 提现方案ID
     * @return 结果
     */
    @Override
    public ServerResponse deleteAppCashschemeById(Integer appCashschemeById) {

        int cashschemeNum = cashschemeMapper.deleteAppCashschemeById(appCashschemeById);
        if (cashschemeNum == 1){
            return ServerResponse.createBySuccess("删除方案成功",cashschemeMapper.selectAppCashschemeList(null));
        }
        return ServerResponse.createByErrorMessage("删除方案失败");
    }
}
